package test.controller;

import model.User;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.SelectEvent;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;

import admin.dao.UserDAO;

public class UserViewCtrlListboxMVC extends SelectorComposer<Component>{
	private static final long serialVersionUID = 1L;

	@Wire
	private Listbox  userViewMVC;
	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		userViewMVC.setModel(new ListModelList<User>(UserDAO.getAllUser()));
		userViewMVC.getPagingChild().setMold("os");
	}
	
	@Listen("onSelect = #userViewMVC")
    public void chooseFood(SelectEvent<?,?> event) {
        SelectEvent<?,?> se = event;
        // Get event target
        Listitem selectedItem = (Listitem) ((Listbox) se.getTarget()).getSelectedItem();
        // Get selected item's value
        User selectedUser = (User) selectedItem.getValue();
        Clients.showNotification("Select "+selectedUser.getUsername(), "info", userViewMVC, "middle_center", 1000);
    }
}
